package com.example.component.analyzer.common.enums;

import com.example.common.api.base.interfaces.IOptCode;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.collections4.CollectionUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *
 * </p>
 *
 * @author Yi
 * @version v1.0.0
 * @date 2019-07-06 20:42
 * @modificationHistory=========================逻辑或功能性重大变更记录
 * @modify By: {修改人} 2019-07-06
 * @modify reason: {方法名}:{原因}
 * ...
 */
@AllArgsConstructor
@Getter
public enum GoldChartDataTypeEnum implements IOptCode<Integer> {

    /**
     * 表格数据加载类型
     */
    GOLD_CHART_DATA_TYPE_DAY(0),
    GOLD_CHART_DATA_TYPE_WEEK(1),
    GOLD_CHART_DATA_TYPE_MONTH(2),
    GOLD_CHART_DATA_TYPE_YEAR(3);

    private Integer type;

    /**
     * 操作码抽象定义
     *
     * @return
     */
    @Override
    public Integer getCode() {
        return getType();
    }

    /**
     * 根据Code找枚举类
     * @param code
     * @return
     */
    public static GoldChartDataTypeEnum codeOf(Integer code) {
        List<GoldChartDataTypeEnum> codes = Arrays.asList(values()).stream().filter(p -> p.getCode().equals(code)).collect(Collectors.toList());
        return CollectionUtils.isEmpty(codes) ? GOLD_CHART_DATA_TYPE_DAY : codes.get(0);

    }

    /**
     * 所有code
     *
     * @return
     */
    public static List<Integer> codes() {
        return Arrays.asList(values()).stream().map(p -> p.getCode()).collect(Collectors.toList());
    }
}
